{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import json\n",
    "import urllib\n",
    "import os\n",
    "import sys\n",
    "from matplotlib import pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data_prefix = './data/imsa'\n",
    "jsonlists = os.listdir(data_prefix)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "569"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(jsonlists)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "jsonlists = [os.path.join(data_prefix,i) for i in jsonlists]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "./data/imsa\\27\n",
      "./data/imsa\\287\n",
      "./data/imsa\\448\n",
      "./data/imsa\\81\n"
     ]
    }
   ],
   "source": [
    "alljson = []\n",
    "for i in jsonlists:\n",
    "    try:\n",
    "        alljson.append(json.load(open(i)))\n",
    "    except:\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fri Nov 03 23:20:44 2017       \n",
      "+-----------------------------------------------------------------------------+\n",
      "| NVIDIA-SMI 385.69                 Driver Version: 385.69                    |\n",
      "|-------------------------------+----------------------+----------------------+\n",
      "| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |\n",
      "| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |\n",
      "|===============================+======================+======================|\n",
      "|   0  GeForce GTX 108... WDDM  | 00000000:04:00.0 Off |                  N/A |\n",
      "| 23%   23C    P8     8W / 250W |    327MiB / 11264MiB |      0%      Default |\n",
      "+-------------------------------+----------------------+----------------------+\n",
      "|   1  GeForce GTX 108... WDDM  | 00000000:82:00.0 Off |                  N/A |\n",
      "| 23%   23C    P8     8W / 250W |    156MiB / 11264MiB |      0%      Default |\n",
      "+-------------------------------+----------------------+----------------------+\n",
      "                                                                               \n",
      "+-----------------------------------------------------------------------------+\n",
      "| Processes:                                                       GPU Memory |\n",
      "|  GPU       PID   Type   Process name                             Usage      |\n",
      "|=============================================================================|\n",
      "|    0      5396    C+G   ...6)\\Google\\Chrome\\Application\\chrome.exe N/A      |\n",
      "|    0      6308    C+G   Insufficient Permissions                   N/A      |\n",
      "|    0      8420    C+G   C:\\Windows\\explorer.exe                    N/A      |\n",
      "|    0      8984    C+G   ...t_cw5n1h2txyewy\\ShellExperienceHost.exe N/A      |\n",
      "|    0      9384    C+G   ...dows.Cortana_cw5n1h2txyewy\\SearchUI.exe N/A      |\n",
      "|    0     10844    C+G   ...rogram Files\\Microsoft VS Code\\Code.exe N/A      |\n",
      "|    1      4260    C+G   Insufficient Permissions                   N/A      |\n",
      "+-----------------------------------------------------------------------------+\n"
     ]
    }
   ],
   "source": [
    "!nvidia-smi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "697535"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alljson[0]['response']['list'][0]['playbook_id']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "one parse failed\n"
     ]
    }
   ],
   "source": [
    "playbook_ids = []\n",
    "for onejson in alljson:\n",
    "    playlist = onejson['response']['list']\n",
    "    for play in playlist:\n",
    "        try:\n",
    "            playbook_ids.append(play['playbook_id'])\n",
    "        except:\n",
    "            print(\"one parse failed\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "56467"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(set(playbook_ids))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import urllib2\n",
    "for playid in playbook_ids:\n",
    "    response = urllib2.urlopen('http://www.example.com/')\n",
    "    html = response.read()"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
